<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>vue3-002</title>
    <script src="./vue3.js"></script>
</head>

<body>
    <div id="app">
        <sun-comp1 :obj="person"></sun-comp1>
        <button @click="change">改变</button>
    </div>
    <script>
        const { createApp, computed, ref, toRefs, reactive, defineComponent } = Vue

        const SunComp1 = defineComponent({
            name: 'SunComp1',
            props: ['obj'],
            template: `
                        <div>
                            <p>姓名：{{ name }}</p>
                            <p>年龄：{{ age }}</p>
                            <p>组合：{{ objMerge }}</p>
                            <p @click="mychange">呵呵呵呵呵呵呵</p>
                        </div>
                    `,
            setup(prop) {
                const { name, age } = toRefs(prop.obj)
                const objMerge = computed(() => {
                    return name.value + ' ' + age.value
                })
                return {
                    name,
                    age,
                    objMerge,
                    mychange: () => {
                        name.value += 1
                    }
                }
            }
        })


        createApp({
            components: {
                SunComp1
            },
            setup() {
                const person = reactive({
                    name: '孙小双', age: 33
                })
                return {
                    person,
                    change: () => {
                        person.name = person.name + '1'
                        person.age++
                    }
                }
            }
        }).mount("#app")
    </script>
</body>

</html>